<template>
  <div>
    <div id="box" v-cloak>
      <!-- 购物车 -->
      <header>
        <div class="on">
          <span class="iconfont" @click="$router.go(-1)">&#xe6bc;</span>
          <h2>购物车</h2>
          <p>
            <span class="iconfont">&#xf0112;</span>
            <i></i>
            <span class="iconfont">&#xe71e;</span>
          </p>
        </div>
        <div class="under">
          <ul>
            <li>
              <span>全部（40）</span>
              <i></i>
            </li>
            <li>降价（4）</li>
            <li>常卖（2）</li>
            <li>
              <em>分类</em>
              <span class="iconfont">&#xe611;</span>
            </li>
          </ul>
        </div>
      </header>
      <!-- main -->
      <main id="main">
        <div class="top">
          <input type="radio" />
          <span class="s1">小U自营</span>
          <span class="s2">已免运费</span>
          <i> </i>
          <span class="s3">领劵</span>
        </div>
        <div class="on">
          <!-- //数据渲染  -->
          <van-swipe-cell v-for="(item, idx) in goodslist" :key="item.id">
            <div class="first">
              <input type="radio" value="true" />
              <img :src="item.img" alt="" />
              <p>
                <span>{{ item.goodsname }} </span>
                <span>比加时优惠￥100</span>
                <span>
                  <i class="i1"> ￥</i>
                  <i class="i2">{{ item.price }} </i>
                  <i class="i3">￥{{ item.price }}</i>
                  <b class="b1">
                    <button type="button">-</button>
                    1
                    <button type="button">+</button>
                  </b>
                </span>
              </p>
            </div>
            <template #right>
              <van-button
                @click="del(idx)"
                square
                text="删除"
                type="danger"
                class="delete-button"
              />
            </template>
          </van-swipe-cell>
        </div>
      </main>
      <!-- #tain -->
      <footer id="tain">
        <div class="top">
          <input type="radio" value="true" />
          <span class="s1">全选</span>
          <p class="p1">
            <span>合计</span>
            <span>已免运费</span>
          </p>
          <p class="p2">
            <span>￥0000</span>
            <span>已优惠￥200</span>
          </p>
          <p class="p3" @click="goOrder()">结算</p>
        </div>
      </footer>
    </div>
  </div>
</template>

<script>
import { cartList , cartDelete} from "../request/api";
export default {
  data() {
    return {
      goodslist: [],
    };
  },
  mounted() {
    let uid = "";
    uid = JSON.parse(sessionStorage.getItem("userinfo")).uid;
    cartList({
      uid,
    }).then((res) => {
      if (res.data.code == 200) {
        this.goodslist = res.data.list;
      }
    });
  },
  methods: {
    //点击结算 跳转到确认订单界面
    goOrder() {
      console.log(666);
      this.$router.push("/order");
    },
    del(id){
      cartDelete({id}).then(res=>{
        if(res.data.code == 200){
          alert('删除成功')
          location.reload()
        }else{
          alert('删除失败')
        }
        
      })
    }
  },
};
</script>

<style scoped>
@import "../assets/css/scar.css";
.van-button {
  height: 100px;
}
</style>
